package com.neo.config;

import javax.servlet.MultipartConfigElement;
import org.springframework.boot.web.servlet.MultipartConfigFactory;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

// todo 添加拦截

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title(AppConfig.appName)
                .description(AppConfig.appName + " API " + AppConfig.version + " document")
                .termsOfServiceUrl(AppConfig.home).version(AppConfig.version)
                .contact(new Contact(AppConfig.name, AppConfig.source, AppConfig.contact)).build();
    }

    // 开放功能
    @Bean
    public Docket vistorapi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("visitor-doc").apiInfo(apiInfo()).select()
                .apis(RequestHandlerSelectors.basePackage("com.neo.visitor.controller")).paths(PathSelectors.any())
                .build();
    }

    // 文件上传
    @Bean
    public Docket uploadapi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("upload-doc").apiInfo(apiInfo()).select()
                // 自行修改为自己的包路径
                .apis(RequestHandlerSelectors.basePackage("com.neo.upload.controller")).paths(PathSelectors.any())
                .build();
    }

    // 功能集成
    // 集成redis
    @Bean
    public Docket redisapi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("redis-doc").apiInfo(apiInfo()).select()
                // 自行修改为自己的包路径
                .apis(RequestHandlerSelectors.basePackage("com.neo.redis.controller")).paths(PathSelectors.any())
                .build();
    }

    // 集成mysql
    @Bean
    public Docket mysqlapi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("mysql-doc").apiInfo(apiInfo()).select()
                // 自行修改为自己的包路径
                .apis(RequestHandlerSelectors.basePackage("com.neo.mysql.controller")).paths(PathSelectors.any())
                .build();
    }

    // 集成palpayapi
    @Bean
    public Docket palpayapi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("palpay-doc").apiInfo(apiInfo()).select()
                // 自行修改为自己的包路径
                .apis(RequestHandlerSelectors.basePackage("com.neo.palpay.controller")).paths(PathSelectors.any())
                .build();
    }

    // @Bean
    // public MultipartConfigElement multipartConfigElement() {
    // MultipartConfigFactory factory = new MultipartConfigFactory();
    // //单个文件最大
    // factory.setMaxFileSize("80MB"); //KB,MB
    // /// 设置总上传数据总大小
    // factory.setMaxRequestSize("102400KB");
    // return factory.createMultipartConfig();
    // }
}
